<template>
	<view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="item in swiperlist">
				<view class="swiper-item">
					<image :src="'http://localhost:8090/foodapp'+item.icon" mode="" style="width: 100%;height: 240px;">
					</image>
				</view>
			</swiper-item>
		</swiper>
		<uni-section title="菜品类别" sub-title="" type="square">
			<uni-grid :column="4">
				<uni-grid-item v-for="(item,index) in typlist">
					<view style="display:flex;flex-direction: column; align-items: center;"
						@click="toTypeListPage(item.typename)">
						<image :src="'http://localhost:8090/foodapp'+item.icon" mode=""
							style="width: 120rpx; height: 120rpx;"></image>
						<view>{{item.typename}}</view>
					</view>
				</uni-grid-item>
			</uni-grid>
		</uni-section>
		<uni-section title="新闻列表" sub-title="" type="square">
			<uni-list >
				<uni-list-item clickable="true" :to="'/pages/newsdetail/newsdetail?id='+item.id" v-for="item,index in newslist" :key="index" 
				:title="item.title"
				:rightText="item.date"></uni-list-item>
			</uni-list>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newslist: [{
					"id": 1,
					"title": "军事新闻1",
					"content": "军事新闻内容",
					"type": "军事",
					"date": "2024-03-01"
				}],
				typlist: [{
					"id": 1,
					"typename": "鱼类",
					"icon": "/images/fish.png"
				}],
				swiperlist: [{
						"id": 1,
						"name": "烤鸭",
						"label": "烤鸭烤鸭烤鸭",
						"icon": "/images/1.png",
						"price": 88,
						"description": "烤鸭烤鸭烤鸭烤鸭烤鸭",
						"type": "肉类"
					},
					{
						"id": 2,
						"name": "回锅肉",
						"label": "回锅肉回锅肉回锅肉",
						"icon": "/images/2.png",
						"price": 12.8,
						"description": "回锅肉回锅肉回锅肉回锅肉回锅肉回锅肉回锅肉回锅肉",
						"type": "肉类"
					},
					{
						"id": 3,
						"name": "茄子",
						"label": "茄子茄子茄子茄子",
						"icon": "/images/3.png",
						"price": 20,
						"description": "茄子茄子茄子茄子茄子茄子茄子",
						"type": "蔬菜"
					},
					{
						"id": 4,
						"name": "宫保鸡丁宫保鸡丁",
						"label": "宫保鸡丁宫保鸡丁宫保鸡丁",
						"icon": "/images/4.png",
						"price": 34.5,
						"description": "宫保鸡丁宫保鸡丁宫保鸡丁",
						"type": "肉类"
					}
				]
			}
		},
		methods: {
			toTypeListPage(typename) {

				uni.setStorageSync('typename', typename)
				uni.switchTab({
					url: '/pages/foodlist/foodlist'
				})

			},
			loadData() {
				// 加载菜品类别
				uni.request({
					url: 'http://localhost:8090/foodapp/types/list',
					method: 'POST',
					data: {},
					success: res => {
						console.log(res);
						this.typlist = res.data.data
					},
					fail: () => {},
					complete: () => {}
				});
				// 加载新闻
				uni.request({
					url: 'http://localhost:8090/foodapp/news/list',
					method: 'POST',
					data: {},
					success: res => {
						console.log(res);
						this.newslist = res.data.data
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad() {
			this.loadData()
		}
	}
</script>

<style>

</style>
